<?php
declare (strict_types=1);

namespace app\course\model\video\admin;

use app\course\model\base\CourseSection as BaseCourseSection;
use app\course\model\video\CourseSectionVideo;
use think\model\concern\SoftDelete;

/**
 * 点播课程--后台管理
 */
class VideoSection extends BaseCourseSection
{
    use SoftDelete;

    /**
     * 全局查询范围
     *
     * @var [type]
     */
    protected $globalScope = ['courseType'];

    /**
     * 定义查询设备类型范围条件
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-03-10
     *
     * @param    [type]                         $query [description]
     * @return   [type]                                [description]
     */
    public function scopeCourseType($query)
    {
        $query->partition('p1');
    }

    /**
     * 新增数据事件
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-03-14
     *
     * @return   string
     */
    public static function onBeforeInsert($course)
    {
        $course->course_type = 1;
    }

    /**
     * 课时数据
     * Author: Martinsun <syh@sunyonghong.com>
     * Date: 2021/9/1
     *
     * @return \think\model\relation\BelongsTo
     */
    public function courseData()
    {
        return $this->belongsTo(CourseSectionVideo::class, 'course_data_id');
    }
}
